<?php
include_once("ui/init.php");
include_once("includes/classes/games.php");
include_once("includes/classes/game.php");
class Index {
	function action($post_vars) {
		$return_str = "";
		switch ($post_vars['action']) {
			default:
			case "wellcome":
				$return_str .= $this->wellcome($post_vars);
				break;
			case "standing":
				$return_str .= $this->standing($post_vars);
				break;
		}
		return $return_str;
	}
	//---------------------------------------------------------
	// Test function
	function standing($post_vars) {
		//Load table data
		$items_list = array(1 => array('usernum' => 3, 
									   'username' => 'ahmet',
										'played' => 153,
									   	'won' => 16,
										'drawn' => 52,
										'lost' => 85,
										'gf' => 79,
										'ga' => 303,
										'avg' => -224,
										'pts' => 100
									   ),
							2 => array('usernum' => 6, 
									   'username' => 'kupaalmaz',
										'played' => 140,
									   'won' => 10,
										'drawn' => 59,
										'lost' => 71,
										'gf' => 63,
										'ga' => 313,
										'avg' => -250,
										'pts' => 89
									   ),
							3 => array('usernum' => 2, 
									   'username' => 'NIHAT',
										'played' => 149,
									   'won' => 11,
										'drawn' => 54,
										'lost' => 84,
										'gf' => 86,
										'ga' => 315,
										'avg' => -229,
										'pts' => 87
									   )
							);
							
		
		$smarty = new _Smarty();
		$smarty->assign ($post_vars);							
		$smarty->assign('items', $items_list);
		return $smarty->fetch ('standing_table.html');			
	}	
	//---------------------------------------------------------
	// Statistik for next game 
	function ngStat($game_id) {
		global $session;
		
		//Load table data
		$smarty = new _Smarty();
		//$smarty->assign ($post_vars);	
		if(isset($_SESSION['statGameId']) && $game_id != 0)
        	$game_id = $_SESSION['statGameId'];
        else
        	$game_id = 0;

		$g = new Game();
		$s = "";
		if (!isset($game_id) || $game_id == 0)
			$s = $g->getNextGame();
		else
			$s = $g->getNextGame((int)$game_id);
		$_SESSION['statGameId'] = $g->id;
		
		$smarty->assign('game', $g);
		$smarty->assign('stats', $g->getStat());
		$smarty->assign('my_session', $session);
		
		return $smarty->fetch ('nextGameStat.html');			
	}
	
	function wellcome($post_vars) {
		global $session;
		
		//Load table data
		$smarty = new _Smarty();
		$smarty->assign('my_session', $session);
		$smarty->assign ($post_vars);			
		$g = new Games();
		$smarty->assign ("userTable", $g->userTable($post_vars));
		return $smarty->fetch("wellcome.html");		
		
	}
}
?>